//
// desc: utils
//
(function(){
	var _p = package('sango.util');
	window.U = _p;

	require('sango.package');

	_p.make_bean = function(_inputs) {
		var _o = new Object(), i, _input;
		for(i=0;i<_inputs.length;++i){
			_input = _inputs[i];
			if(!!_input.name) {
				_o[_input.name]=_input.value;
			}
		}
		return _o;
	};
	_p.post_json = function(_url,_data,_callback) {
		$.ajax({
			url:_url,
			data: _data ? JSON.stringify(_data) : null,
			success: _callback,
			type: 'post',
			dataType: 'json',
			contentType: 'application/json; charset=utf-8'
		});
	};
	_p.get_json = function(_url,_data,_callback) {
		$.ajax({
			url:_url,
			data: _data ? JSON.stringify(_data) : null,
			success: _callback,
			type: 'get',
			dataType: 'json',
			contentType: 'application/json; charset=utf-8'
		});
	};
	//
	// extend util
	//
	_p._format_pattern = /\{([\w\d]+)\}/g;
	String.prototype.format = function() {
		var _vals = arguments;
		return this.replace(_p._format_pattern, function(_a,_b,_c){
			return _vals[_b];
		});
	};
})();


